package com.aaa.static2;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @Description:
 * @author:LiWei
 * @date:2022年11月09日9:50
 */
public class Proxy1 {

    private ChuZu target;
    public Proxy1(ChuZu target) {
        this.target = target;
    }
    public ChuZu getInstance(){

        ClassLoader loader=target.getClass().getClassLoader();
        Class<?>[] interfaces=target.getClass().getInterfaces();
        InvocationHandler invocationHandler=new InvocationHandler(){
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                intro();
                watch();
                Object result=method.invoke(target,args);
                return result;
            }

        };
        Object object= Proxy.newProxyInstance(loader,interfaces,invocationHandler);
        return (ChuZu) object;
    }
    public void watch(){
        System.out.println("看房");
    }
    public void intro(){
        System.out.println("介绍");
    }
}








